package com.kktestspb.demo.services;


import com.kktestspb.demo.dao.UserDaoInt;
import com.kktestspb.demo.polo.User;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import org.slf4j.Logger;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServices {

    private final Logger logger= LoggerFactory.getLogger(this.getClass());

    @Autowired
    UserDaoInt userDaoInt;
    @Autowired
    User user;

    public List<User> getUserList(){
        return userDaoInt.getUserList();
    }
    public User getUserById(String uid){
        return userDaoInt.getUserById(uid);
    }

    public void updateUser(User user){
        User u1=this.getUserById(user.getuId());
        Long relong=userDaoInt.updateUser(user);
        if (relong!=0){
            logger.info("【更新用户信息成功！！！】原用户信息为"+u1.toString()+"...更新后为："+user.toString());
        }
        else{
            logger.info("【更新用户信息失败...】用户信息为"+user.toString());
        }

    }
    public void deleteUser(String id){
        Long relong=userDaoInt.deleteUser(id);
        if(relong!=0){
            logger.info("【删除用户成功！！！】用户id为："+id);
        }else {
            logger.info("【删除用户失败...】用户id为："+id);
        }
    }

    public void addUser(User user){
        userDaoInt.insertUser(user);
    }

}
